package com.asiainfo.service;
/*
 * 
 * 排课信息service
 */
import java.util.Date;
import com.asiainfo.bean.Coach;
import com.asiainfo.bean.Course;
import com.asiainfo.bean.Schedule;
import com.asiainfo.dao.Schedule_Dao;

public class ScheduleService {
	@SuppressWarnings("deprecation")
	//增加排课
	public void addSchedule(String[] args) {
		if (args.length != 4) {
			System.out.println("对不起，请输入合法参数");
			return;
		}
		CourseService cs = new CourseService();
		Course course = cs.findCourseByName(args[2]);
		if (course == null) {

			return;
		}
		CoachService coachservice = new CoachService();
		Coach coach = coachservice.findCoachByName(args[3]);
		if (coach == null) {

			return;
		}
		Date date = new Date(Integer.parseInt(args[1].substring(0, 3)), Integer.parseInt(args[1].substring(4, 5)),
				Integer.parseInt(args[1].substring(6, 7)), Integer.parseInt(args[1].substring(9, 10)),
				Integer.parseInt(args[1].substring(11, 12)));

		Schedule schedule = findScheduleByTime((int) date.getTime());
		if (schedule != null) {
			System.out.println("该时间已排课");
			return;
		}
		schedule = new Schedule((int) date.getTime(), course.getCourse_id(), coach.getCoach_id(), 30, 0);
		Schedule_Dao sd = new Schedule_Dao();
		int result = sd.addSchedule(schedule);
		if (result > 0) {
			System.out.println("排课成功");
		} else {
			System.out.println("排课失败");
		}
	}
	//查找某个时间点的排课
	public Schedule findScheduleByTime(int time) {
		Schedule_Dao sd = new Schedule_Dao();
		return sd.getscheduleByTime(time);
	}
}
